﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;

namespace bjcl_wmp.Models
{
    public class Library
    {
        public List<MyMedia> Medias { get; private set; }

        public void ImportLibrary(string _filename)
        {
            if (this.Medias == null)
                this.Medias = new List<MyMedia>();
            XDocument xml = XDocument.Load(_filename);
            var result = from e in xml.Root.Descendants("item")
                         select new
                         {
                             MyName = e.Element("name").Value,
                             MyUri = e.Element("uri").Value,
                             MyType = e.Element("type").Value
                         };
            foreach (var item in result)
            {
                this.Medias.Add(new MyMedia() { Name = item.MyName, MyUri = new Uri(item.MyUri), MyType = item.MyType });
            }
        }
    }
}
